package com.example.my_2048.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.my_2048.R;

/**
 * Created by tang on 16/8/19.
 */
public class CardView extends FrameLayout{

    private TextView tvScores;

    private int iScores;

    public CardView(Context context) {
        super(context);
        initView();
    }

    public CardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    public CardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView()
    {


        tvScores=new TextView(getContext());
//        this.setBackgroundColor(Color.RED);
        tvScores.setText("A");

        LayoutParams lp=new LayoutParams(-1,-1);
        tvScores.setGravity(Gravity.CENTER);
        tvScores.setTextSize(35);
        tvScores.setBackgroundResource(R.color.colorCard);
        iScores=0;
        showTvScores();
        addView(tvScores,lp);
    }

    public void showTvScores() {

        tvScores.setText(iScores!=0?String.valueOf(iScores):"");
    }

    public void addScores(int i)
    {
        iScores+=i;
        showTvScores();
    }

    public int getiScores() {
        return iScores;
    }

    public void setiScores(int iScores) {
        this.iScores = iScores;
    }
}
